package com.zhengtoudai.ui.fragment;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zhengtoudai.R;
import com.zhengtoudai.base.App;
import com.zhengtoudai.base.BaseFragment;
import com.zhengtoudai.global.Config;
import com.zhengtoudai.ui.activity.WebViewActivity;
import com.zhengtoudai.util.Tool;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 作者：黑哥 on 2016/7/29 11:21
 */
public class MoreFragment extends BaseFragment {
    @Bind(R.id.tv_wechat)
    TextView mTvWechat;
    @Bind(R.id.tv_service_telephone)
    TextView mTvServiceTelephone;
    @Bind(R.id.textView)
    TextView mTextView;
    private View view;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_more, container, false);
        super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    protected void initTitle() {
        titleUtil.setTitle("更多", false);
    }

    @Override
    protected void initView() {
        mTvServiceTelephone.setText(App.mApp.getSession().get("customPhone"));
        mTvWechat.setText(App.mApp.getSession().get("weChatCode"));
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }


    @OnClick({R.id.tv_about_us, R.id.rl_wechat,R.id.rl_service_telephone})
    public void onClick(View view) {
        if (Tool.isFastDoubleClick()) return;
        switch (view.getId()) {
            case R.id.tv_about_us:
                Bundle bundle = new Bundle();
                bundle.putString("title", "关于我们");
                bundle.putString("url", Config.BASE_URL+"web/companyIntroduction.do");
                startActivity(bundle, WebViewActivity.class);
                break;
            case R.id.rl_wechat:
                ClipboardManager cmb= (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
                cmb.setPrimaryClip(ClipData.newPlainText(null, mTvWechat.getText().toString()));
                Snackbar.make(mTvWechat,"微信号已复制",Snackbar.LENGTH_LONG)
                .setAction("是否前去微信?", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        try{
                            Intent intent = new Intent();
                            intent.setComponent(new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI"));
                            intent.setAction(Intent.ACTION_VIEW);
                            startActivity(intent);
                        }catch (Exception e){
                            Snackbar.make(mTvWechat,"您没有安装微信,请先安装微信",Snackbar.LENGTH_LONG).show();
                        }

                    }
                }).show();
                break;
            case R.id.rl_service_telephone:
                Intent intent=new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"+mTvServiceTelephone.getText().toString()));
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
                break;
        }
    }
}
